<template>
    <div class="reset_admin_form_container">
        <el-form :model="formData" status-icon :rules="rules" ref="modifyForm" label-width="100px"
                 class="demo-ruleForm" style="padding-top: 18px;">
            <el-form-item label="账套" prop="code">
                <el-input v-model="formData.code" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="登录账号" prop="admin">
                <el-input v-model="formData.user_login_id" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="新设密码" prop="password">
                <el-input type="text" v-model="formData.password" clearable></el-input>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
import md5 from 'js-md5';

export default {
    name: 'ResetAdmin',
    props: {
        propsData: {
            type: Object,
            default() {
                return {
                    init: true,
                };
            },
        },
    },
    data() {
        return {
            //弹窗option
            dialogOption: {
                visible: false,
            },
            formData: {},
            rules: {
                password: [
                    { required: true, message: '请输入新密码', trigger: 'blur' }, ],
            }
        };
    },
    watch: {
        propsData: {
            handler() {
                this.init();
            },
            deep: true,
            immediate: true,
        },
    },
    methods: {
        init() {
            const _this = this;
            if (_this.propsData.init) {
                return;
            }
            if (_this.$refs.modifyForm) {
                _this.$refs.modifyForm.clearValidate();
            }
            _this.formData = $.extend({}, {
                code:_this.propsData.row.code,
                sid:_this.propsData.row.sid,
                password: _this.propsData.row.sid,
                user_login_id: _this.propsData.row.sid,
            });
        },
        async confirm() {
            const _this = this;
            let valid = await _this.validateForm('modifyForm');
            if (valid) {
                let subData = $.extend({}, _this.formData);
                subData.password = md5(subData.password);
                return _this.fetchData(_this.$api.API_ResetSysAccountSetAdminUser, subData).then(() => {
                    _this.$message.success('重置成功！');
                    return true;
                }).catch(() => {
                    return false;
                });
            }
            return valid;
        },
    },
};
</script>
<style lang="less" rel="stylesheet/less">
.reset_admin_form_container {
    width: 100%;
    height: 100%;
    overflow: hidden;
}
</style>
